package com.longge;

import java.util.Objects;
import java.util.PriorityQueue;

public class SplitNum {

    public int splitNum(int num) {

        String strNum = String.valueOf(num);
        char[] chars = strNum.toCharArray();
        PriorityQueue<Character> pq = new PriorityQueue<>();
        for (char aChar : chars) {
            pq.offer(aChar);
        }
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        while (!pq.isEmpty()) {

            Character poll1 = pq.poll();
            sb1.append(poll1);
            Character poll2 = pq.poll();
            if (Objects.nonNull(poll2)) {
                sb2.append(poll2);
            }
        }
        return Integer.parseInt(sb1.toString()) + Integer.parseInt(sb2.toString());

    }


}
